﻿<Window xmlns:Views="clr-namespace:VehicleRental.WpfClient.Views"  x:Class="VehicleRental.WpfClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:viewModel="clr-namespace:VehicleRental.WpfClient.ViewModels"
        Title="MainWindow" Height="630" Width="525" ResizeMode="NoResize">
    <Window.DataContext>
        <viewModel:AppViewModel />
    </Window.DataContext>
    <Window.Resources>
        <DataTemplate 
            DataType="{x:Type viewModel:PublicVehicleRentalVIewModel}">
            <Views:PublicPlacesView/>
        </DataTemplate>
        <DataTemplate            
            DataType="{x:Type viewModel:LoginRegisterFormViewModel}">
            <Views:LoginRegisterFormView/>
        </DataTemplate>
        <DataTemplate            
            DataType="{x:Type viewModel:PrivateVehicleRentalViewModel}">
            <Views:PrivatePlacesView/>
        </DataTemplate>
        <BooleanToVisibilityConverter x:Key="BoolToVis" />
    </Window.Resources>

    <Grid>
        <DockPanel>
            <StackPanel Name="HeaderContainer"
                    DockPanel.Dock="Top">
                <ItemsControl ItemsSource="{Binding ViewModels}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Button Content="{Binding Name}"
                                    Command="{Binding Path=DataContext.ChangeViewModel, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                                    CommandParameter="{Binding}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <Button Content="Login/Register" Command="{Binding Login}" Visibility="{Binding Path=AnonymousUser, Converter={StaticResource BoolToVis}}"></Button>
                <Button Content="Logout" Command="{Binding Logout}" Visibility="{Binding Path=LoggedInUser, Converter={StaticResource BoolToVis}}"></Button>
            </StackPanel>
            <ContentControl DockPanel.Dock="Bottom"
                            Content="{Binding CurrentViewModel}"/>
        </DockPanel>
    </Grid>
</Window>
